package de.baumann.browser.activitys.hash

import android.annotation.SuppressLint
import android.app.Activity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.RadioButton
import android.widget.RadioGroup
import com.amap.api.maps.AMap
import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.MapView
import com.amap.api.maps.model.MyLocationStyle
import de.baumann.browser.R
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IBaseView
import de.baumann.browser.units.LocationUnit
import kotlinx.android.synthetic.main.include_tool_bar.*

/**
 *@author:junce
 *@date:2019/3/7 10:58
 *@discription: 推广位置
 */

class PackLocationActivity : BaseOdinActivity<IBaseView, BasePresenter<IBaseView>>() {


    override fun createPresenter(): BasePresenter<IBaseView>? {
        return null
    }

    override fun createView(): IBaseView? {
        return null
    }

    private lateinit var rgLocation: RadioGroup
    private lateinit var rbCity: RadioButton
    private lateinit var rbCountry: RadioButton
    private lateinit var location: String
    private var city = ""

    override fun getTitleText(): String {
        return getString(R.string.sponsored_location)
    }

    override fun getLayout(): Int {
        return R.layout.activity_pack_location
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        rgLocation = findViewById(R.id.rgLocation)
        rbCity = findViewById(R.id.rbCity)
        rbCountry = findViewById(R.id.rbCountry)
    }


    @SuppressLint("SetTextI18n")
    override fun initData() {
        location = getString(R.string.national)
        LocationUnit.initLocation(mContext) { p0 ->
            LocationUnit.stopLocation()
            city = p0.city
            rbCity.text = "当前城市：$city"
        }
        LocationUnit.startLocation()
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_ok, menu)
        return super.onCreateOptionsMenu(menu)
    }


    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (rbCity.isChecked && !city.isEmpty()) {
            location = city
        } else {
            LocationUnit.startLocation()
        }

        if (rbCountry.isChecked) {
            location = getString(R.string.national)
        }

        setResult(Activity.RESULT_OK, intent.putExtra("location", location))
        finish()
        return super.onOptionsItemSelected(item)
    }

    override fun onStop() {
        super.onStop()
        LocationUnit.stopLocation()
    }

}
